<?php
//Initial date: 2009-05-13
//Last change: 2009-05-31 by Kamil Jaskiewicz

class tasks extends DBTable
{
	public $DB;

	public function __construct($ID=false)
	{
		parent::__construct("tasks");
		if ($ID) {
			$this->findID($ID);
		}
	}

	public function findID($id) {
		$this->DB->query("SELECT * FROM vw_tasks WHERE task_id='$id'");
		return $this->getNext();
	}
	
	public function selectAll()
	{
		$this->DB->query("SELECT * FROM vw_tasks");
		return $this->DB->RowCount;
	}

	public function selectContactsForTask($id)
	{
		$this->DB->query("SELECT tc.*, CONCAT(c.contact_first_name, ' ', c.contact_last_name) AS contact_name FROM task_contacts AS tc LEFT JOIN contacts AS c ON tc.contact_id=c.contact_id WHERE tc.task_id='$id'");
		return $this->DB->RowCount;
	}

	public function getPossibleStatusValues()
	{
		$this->DB->query("SELECT * FROM dictionary WHERE dict_group='task_status'");
		return $this->DB->RowCount;
	}

	public function getPossibleTypeValues()
	{
		$this->DB->query("SELECT * FROM dictionary WHERE dict_group='task_type'");
		return $this->DB->RowCount;
	}

	public function delete($id)
	{
		$this->DB->query("DELETE FROM projects WHERE project_id='$id'");
		return $this->DB->RowCount;
	}

	public function deleteContactForTask($contact_id, $t_id)
	{
		$this->DB->query("DELETE FROM task_contacts WHERE contact_id='$contact_id' AND task_id='$t_id'");		
		return $this->DB->RowCount;
	}

}

?>
